<?php
class User_model extends CI_Model
{
	function __construct()
	{
		parent::__construct();
	}
	function getForUser($user=null)
	{
		$this->db->select();
		$this->db->from('user');
		$this->db->where('user',$user);
		$this->db->limit(1);
		return $this->db->get()->result_array();
	}
	function getForId($user_id)
	{
		$this->db->select();
		$this->db->from('user');
		$this->db->join('post_adduser','post_adduser.user_id=post_user.id');
		$this->db->where('post_user.id',$user_id);
		$this->db->limit(1);
		$result = $this->db->get()->result_array();
		if($result[0]['avatar'] == '')
		{
			$result[0]['avatar'] = '/img/defult_face.gif';
		}
		return $result;
	}
	function updateUser($data)
	{
		$this->db->where('id', $data['user_id']);
		unset($data['user_id']);
		$this->db->update('user', $data);
	}
	function addUser($data)
	{
		$data['cre_time'] = time();
		$this->db->insert('user',$data);
		$user_id = $this->db->insert_id();
		$this->db->insert('adduser',array('user_id'=>$user_id));
	}
}